/**
 * org.vz.product.collect.maintain.service.impl
 * @since : jdk 1.8
 */
package org.vz.product.collect.maintain.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.vz.product.collect.maintain.dao.PlatformOverviewDao;
import org.vz.product.collect.maintain.domain.PlatformOverEntity;
import org.vz.product.collect.maintain.domain.entity.PlatformOverResult;
import org.vz.product.collect.maintain.service.PlatformOverviewService;

/**
 * @author Morik is Yongxu.Wang 平台运行总览
 * @CreateTime 2017年09月29日 11:18:04
 * @version 1.0.0
 * @description TODO
 */
@Service
public class PlatformOverviewServiceImpl implements PlatformOverviewService {
	@Autowired
	PlatformOverviewDao platformOverviewDao;

	@Override
	public PlatformOverResult getData(String starTime,String endTime) {
		PlatformOverResult PlatformOverResult = new PlatformOverResult();
		Map<String, String> map = new HashMap<String, String>();
		// yyyy-MM-dd HH:mm:ss
		map.put("starTime", starTime);
		map.put("endTime", endTime);
		List<PlatformOverEntity> select = platformOverviewDao.getSQLManager()
				.select("messagelog.getData", PlatformOverEntity.class, map);

		if (select != null) {
			PlatformOverResult.msg = "查询成功!!!";
			PlatformOverResult.status = 1;
		}
		int sum = 0;
		int successfulNum = 0;
		for (PlatformOverEntity platformOverEntity : select) {
			int itemNum = platformOverEntity.getStatecount();
			int item = platformOverEntity.getState();
			sum += itemNum;
			if (item == 0 || item == 1) {
				PlatformOverResult.data.problemsNum = itemNum;
				successfulNum += itemNum;
			} else if (item == 3) {
				PlatformOverResult.data.pendingNum = itemNum;
			} else if (item == 2) {
				PlatformOverResult.data.problemsNum = itemNum;
			}
		}
		float healthNum = (float) successfulNum / (float) sum;
		PlatformOverResult.data.healthNum = healthNum;
		return PlatformOverResult;
	}
}
